using System;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CommonLibrary.WebControls
{
	[ToolboxData("<{0}:MenuHyperLink runat=\"server\" id=\"MenuHyperLink1\" />")]
	public class MenuHyperLink : HyperLink
	{
		private string _selectedClassName = "selected";
		private bool _isDefault = false;

		/// <summary>
		/// If true, this is the root/default link and will look for 'default.asx' not its target link
		/// </summary>
		public bool IsDefault
		{
			get { return _isDefault; }
			set { _isDefault = value; }
		}

		/// <summary>
		/// The class attribute to apply to this link when selected.  'selected' is default
		/// </summary>
		public string SelectedClassName
		{
			get { return _selectedClassName; }
			set { _selectedClassName = value; }
		}

		protected override void Render(HtmlTextWriter writer)
		{
			string compareUrl;
			if (IsDefault) compareUrl = "/default.aspx";
			else compareUrl = NavigateUrl.Replace("/", "");
			if (Page.Request.PhysicalPath.Equals(Page.Server.MapPath(compareUrl), StringComparison.OrdinalIgnoreCase))
			{
				CssClass = SelectedClassName;
			}

			base.Render(writer);
		}
	}
}